package personal.xjl._23java1studentdemo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import personal.xjl._23java1studentdemo.mapper.TeacherMapper;
import personal.xjl._23java1studentdemo.model.Teacher;
import personal.xjl._23java1studentdemo.service.TeacherService;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    TeacherMapper teacherMapper;
    @Override
    public List<Teacher> findAll() {
        return teacherMapper.selectAll();
    }

    @Override
    public int remove(int id) {
        return teacherMapper.delete(id);
    }

    @Override
    public int add(Teacher teacher) {
        return teacherMapper.insert(teacher);
    }

    @Override
    public Teacher findById(int id) {return teacherMapper.selectById(id);
    }

    @Override
    public int edit(Teacher teacher) {return teacherMapper.update(teacher);
    }

    @Override
    public List<Teacher> findByPage(int currPage, int pageSize) {
        int fromIndex = (currPage<1)?0:(currPage-1)*pageSize;
        return teacherMapper.selectByPage(fromIndex, pageSize);
    }

}
